﻿// // ******************************************************************
// //       /\ /|       @file       LanguageService.cs
// //       \ V/        @brief      await29
// //       | "")       @author     Await, 285283010@qq.com
// //       /  |
// //      /  \\        @Modified   2024-12-31 20:12
// //    *(__\_\        @Copyright  Copyright (c) , 2024-12-25 18:12 Await
// // ******************************************************************

using AutomaticSubtitles.Contracts.Dto;
using AutomaticSubtitles.Contracts.Entity;
using AutomaticSubtitles.Contracts.Vo;
using AutomaticSubtitles.Service.Application.Language.Commands;
using AutomaticSubtitles.Service.Application.Language.Queries;

namespace AutomaticSubtitles.Service.Services;

[Tags("翻译语言配置")]
public class LanguageService : BaseService<LanguageService>
{
    [EndpointDescription("获取语言下拉框列表")]
    [EndpointName("获取语言下拉框列表")]
    [EndpointSummary("获取语言下拉框列表")]
    [Authorize]
    public async Task<ResponseModel<IReadOnlyList<LocalizationOption<string>>?>> GetLanguageAsync()
    {
        var getListLanguageQuery = new GetListLanguageQuery();
        await PublishAsync(getListLanguageQuery);
        return getListLanguageQuery.Result.CreateResult();
    }

    [EndpointSummary("新增语言列表")]
    [EndpointDescription("新增语言列表")]
    [Authorize]
    public async Task<ResponseModel<int>> AddLanguageAsync(LanguageVo data)
    {
        var getListLanguageQuery = new AddLanguageCommand(data);
        await PublishAsync(getListLanguageQuery);
        return getListLanguageQuery.Result.CreateResultAdd();
    }

    [EndpointSummary("删除语言列表")]
    [EndpointDescription("删除语言列表")]
    [Authorize]
    public async Task<ResponseModel<int>> DeleteLanguageAsync(string id)
    {
        var getListLanguageQuery = new DeleteLanguageCommand(id);
        await PublishAsync(getListLanguageQuery);
        return getListLanguageQuery.Result.CreateResultDelete();
    }

    [EndpointSummary("修改语言列表")]
    [EndpointDescription("修改语言列表")]
    [Authorize]
    public async Task<ResponseModel<int>> UpdateLanguageAsync(LanguageVo data)
    {
        var getListLanguageQuery = new UpdateLanguageCommand(data);
        await PublishAsync(getListLanguageQuery);
        return getListLanguageQuery.Result.CreateResultUpdate();
    }

    [EndpointSummary("获取语言列表")]
    [EndpointDescription("获取语言列表")]
    [Authorize]
    public async Task<ResponseModel<IReadOnlyList<LanguageDto>?>> GetLanguageListAsync()
    {
        var getListLanguageQuery = new GetLanguageListDataQuery();
        await PublishAsync(getListLanguageQuery);
        return getListLanguageQuery.Result.CreateResult();
    }
}